<?php /** @noinspection PhpMethodParametersCountMismatchInspection */

use Dingo\Api\Routing\Router;

$api = app(Router::class);

$params = [
    'middleware' => [
        'api.throttle',  // 访问限流
        'serializer:array',  // 减少transformer的包裹层（dingo-serializer-switch插件）
        'bindings'  // 支持路由模型注入（kernel.php配置）
    ],
    'limit' => 60,
    'expires' => 1
];

$api->version('v1',$params, function ($api) {
    /**
     * 需要登录的接口
     */
    $api->group(['middleware' => [
        'api.auth',
    ]],function ($api){
        /**
         * 公共接口
         */
//        初始化
        $api->get('common/init',[\App\Http\Controllers\Auth\LoginController::class,'init'])->name('init');
//        个人信息
        $api->get('common/personal',[\App\Http\Controllers\Auth\LoginController::class,'personal'])->name('personal');
//        一级菜单
        $api->get('common/menuForMenu',[\App\Http\Controllers\Api\MenuController::class,'menuForMenu'])->name('menuForMenu');
//        二级菜单
        $api->get('common/menuForPerm',[\App\Http\Controllers\Api\MenuController::class,'menuForPerm'])->name('menuForPerm');
//        所有角色
        $api->get('common/roles',[\App\Http\Controllers\Api\RoleController::class,'roles'])->name('roles');
//        角色等级
        $api->get('common/level',[\App\Http\Controllers\Api\RoleController::class,'level'])->name('level');
        /**
         * 需要权限的接口
         */
        $api->group(['middleware' => [
//        'check.permission'
        ]],function ($api){
//            用户状态
            $api->patch('users/{user}/status',[\App\Http\Controllers\Api\UserController::class,'status'])->name('StatusUser');
//            用户管理资源路由
            $api->resource('users',\App\Http\Controllers\Api\UserController::class,[
                'except' => ['show'],
                'names' => [
                    'index'   => 'GetUser',
                    'store'   => 'AddUser',
                    'update'  => 'EditUser',
                    'destroy' => 'DelUser'
                ]
            ]);
//            地址状态
            $api->patch('address/{address}/status',[\App\Http\Controllers\Api\AddressController::class,'status'])->name('StatusAddress');
//            地址管理资源路由
            $api->resource('address',\App\Http\Controllers\Api\AddressController::class,[
                'except' => ['show'],
                'names' => [
                    'index'   => 'GetAddress',
                    'store'   => 'AddAddress',
                    'update'  => 'EditAddress',
                    'destroy' => 'DelAddress'
                ]
            ]);
//            权限管理资源路由
            $api->resource('permission',\App\Http\Controllers\Api\PermissionController::class,[
                'except' => ['show'],
                'names' => [
                    'index'   => 'GetPerm',
                    'store'   => 'AddPerm',
                    'update'  => 'EditPerm',
                    'destroy' => 'DelPerm'
                ]
            ]);
//            角色管理资源路由
            $api->resource('role',\App\Http\Controllers\Api\RoleController::class,[
                'except' => ['show'],
                'names' => [
                    'index'   => 'GetRole',
                    'store'   => 'AddRole',
                    'update'  => 'EditRole',
                    'destroy' => 'DelRole'
                ]
            ]);
//            给角色添加权限
            $api->post('role/{role}/perm',[\App\Http\Controllers\Api\RoleController::class,'addPerm'])->name('PermRole');
//        菜单管理资源路由
            $api->resource('menu',\App\Http\Controllers\Api\MenuController::class,[
                'except' => ['show'],
                'names' => [
                    'index'   => 'GetMenu',
                    'store'   => 'AddMenu',
                    'update'  => 'EditMenu',
                    'destroy' => 'DelMenu'
                ]
            ]);
//        菜单状态
            $api->patch('menu/{menu}/status',[\App\Http\Controllers\Api\MenuController::class,'status'])->name('StatusMenu');
        });
    });
});
